package com.topboya.linker.ui.presenter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.topboya.linker.AppConst;
import com.topboya.linker.R;
import com.topboya.linker.api.ApiRetrofit;
import com.topboya.linker.exception.ServerException;
import com.topboya.linker.model.response.BaseResponse;
import com.topboya.linker.model.response.VisitTypeResponse;
import com.topboya.linker.ui.activity.CreateTaskActivity1;
import com.topboya.linker.ui.activity.MainActivity;
import com.topboya.linker.ui.base.Presenter.BasePresenter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.view.CreateTaskView;
import com.topboya.linker.utils.LogUtils;
import com.topboya.linker.utils.UIUtils;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CreateTaskPrensenter extends BasePresenter<CreateTaskView> {


    private static final String TAG = "CreateTaskPrensenter:";

    public CreateTaskPrensenter(BaseActivity context) {
        super(context);

    }

    public void createTaskSuccess(String orgId , String orgName, String createDate, String timeUse, String startTime,String endTime,String cusList, String followName, String followId, String remarks , String Mflage) {

        mContext.showWaitingDialog(UIUtils.getString(R.string.please_wait));
        ApiRetrofit.getInstance().createTask(orgId ,orgName,createDate,timeUse,startTime,endTime,cusList,followName,followId,remarks ,Mflage)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(createtaskreponse -> {
                    String success = createtaskreponse.getMeta().getSuccess();
                    mContext.hideWaitingDialog();
                    if (null != success && Boolean.parseBoolean(success)) {
//                       表示创建任务成功
                        getView().createTaskSuccess();

                    }
                }, this::loginError);
    }

//获取学术类型
    public void getVisitType() {

        mContext.showWaitingDialog(UIUtils.getString(R.string.please_wait));
        ApiRetrofit.getInstance().getVisitType("m_visit_type")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(visittyperesponse -> {
                    String success = visittyperesponse.getMeta().getSuccess();
                    mContext.hideWaitingDialog();
                    if (null != success && Boolean.parseBoolean(success)) {

                        List<VisitTypeResponse.Data> data = visittyperesponse.getData();
                        getView().getVisitType(data);
                    }
                }, this::loginError);
    }

    private void loginError(Throwable throwable) {

        LogUtils.v(throwable.getLocalizedMessage());
//        UIUtils.showToast(throwable.getLocalizedMessage());
        LogUtils.v(TAG + "loginError:" + throwable.getLocalizedMessage());
        mContext.hideWaitingDialog();
    }


}
